package com.sky.controller.admin;

import com.sky.dto.*;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RequestMapping("/admin/order")
@RestController("adminOrderController")
public class OrderController {
    @Autowired
    private OrderService orderService;
    /**
     * 订单搜索
     * @param
     * @return
     *
     */
    @GetMapping("/conditionSearch")
    public Result<PageResult> selectConditions (OrdersPageQueryDTO ordersPageQueryDTO){

        PageResult pageResult =   orderService.selectConditions (ordersPageQueryDTO);
        return Result.success(pageResult);
    }
    /**
     * 各个状态的订单数量统计
     */
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> countByStatus (){

        OrderStatisticsVO orderStatisticsVO = orderService.countByStatus ();
        return Result.success(orderStatisticsVO);
    }

    /**
     * 查询订单详情
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    public Result<OrderVO> selectOrderDetail (@PathVariable Long id){

        OrderVO orderVO = orderService.selectOrderDetail (id);
        return Result.success(orderVO);
    }
    /**
     * 接单
     */
    @PutMapping("/confirm")
    public Result orderTaking (@RequestBody OrdersConfirmDTO ordersDTO){

         orderService.orderTaking(ordersDTO);

        return Result.success();
    }

    /**
     * 拒单
     */
    @PutMapping("/rejection")
    public Result ejectOrder (@RequestBody OrdersRejectionDTO ordersRejectionDTO){

        orderService.ejectOrder (ordersRejectionDTO);

        return Result.success();
    }
    /**
     * 管理端取消订单
     */
    @PutMapping("/cancel")
    public Result cancelOrderAdmin (@RequestBody OrdersCancelDTO ordersCancelDTO){

      orderService.cancelOrderAdmin(ordersCancelDTO);

        return Result.success();
    }
    /**
     * 派送订单
     */
    @PutMapping("/delivery/{id}")
    public Result handOutOrder (@PathVariable Long id){

        orderService.handOutOrder(id);

        return Result.success();
    }
    /**
     * 完成订单
     */
    @PutMapping("/complete/{id}")
    public Result completeOrder (@PathVariable Long id){

        orderService.completeOrder(id);

        return Result.success();
    }
}
